
import wx


class StatusBar:
    # CoreApp StatusBar
    # -------------------------------------------
    # the statusbar is separated with
    # |--- menu help strings ---|-1-|-2-|
    #
    # -1-: current position and selected length
    # -2-: opened document status, 3 letters for ctx1, ctx2, and tree view
    #      B is binary for ctx1 and ctx2 and P for plain text,
    #      T for active tree
    # -3-: current active view from the splitted child window, it can be XVT
    # -4-: short names for the converter (3 characters)
    # -5-: short names for the formatter (3 characters)
    # -6-: opened document size
    # -7-: generated data size

    INFO_SELECTED = 0x01
    INFO_CTX = 0x02
    VIEW_ACTIVE = 0x03
    SHORTNAME = 0x04
    SHORTNAME2 = 0x05
    SIZE_CTX = 0x06
    SIZE_CTX2 = 0x07
    NB_FIELD = 0x08

    def __init__(self, app, parent):
        self.statusbar = parent.CreateStatusBar(StatusBar.NB_FIELD,
                                                wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-8, -4, -1, -1, -1, -2, -3, -3])

    def update(self, value, column):
        if value is not None:
            self.statusbar.SetStatusText(value, column)

    def cleanup(self):
        for k in range(StatusBar.NB_FIELD):
            self.statusbar.SetStatusText('', k)
